package com.lty.bio.demo1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		ServerSocket serverSocket;
		Socket socket = null;
		InputStream is = null;
		try {
			serverSocket = new ServerSocket(15600);
			socket = serverSocket.accept();
			System.out.println("Connected: " + socket.getRemoteSocketAddress());
			is = socket.getInputStream();
		} catch (IOException e1) {
			e1.printStackTrace();
		}

		InputStreamReader isr = new InputStreamReader(is);
		BufferedReader br = new BufferedReader(isr);

		while (true) {
			try {
				String line = null;
				while ((line = br.readLine()) != null) {
					System.out.println(line);
				}
			} catch (Exception e) { // 客户端断开的情况
				System.out.println("Connection Close");
				// break;
			}
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
